package se.energimyndigheten.lampguiden;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.util.Log;

/**
 * This interface help fragments to call their parent activity (that implements FragmentSwapper) to make fragment transitions.
 */
public class SwappableListFragment extends android.support.v4.app.ListFragment {
	protected FragmentSwapper mSwapper;
	
	protected void addFragmentSwapper(Activity swapper) {
		try {
			mSwapper = (FragmentSwapper) swapper;
		} catch (ClassCastException cce) {
			Log.d("Swappable" , "CLASSCASTEXCEPTION");
			cce.printStackTrace();
		}
	}

	protected void swapFragment(Fragment fragment, boolean addToBackStack) {
		if (mSwapper == null) {
			addFragmentSwapper(getActivity());
		}
		mSwapper.swapFragment(fragment, addToBackStack);
	}
}
